﻿#include "logger.h"  

Log::Log()
	:m_bEnabled(true)
{
}

Log::~Log()
{
}

bool Log::Open(string sFileName)
{
	m_tOLogFile.open(sFileName.c_str(), ios_base::out | ios_base::app);
	if (!m_tOLogFile)
	{
		return false;
	}
	return true;
}

void Log::Close()
{
	if (m_tOLogFile.is_open())
	{
		m_tOLogFile.close();
	}
}

bool Log::CommonLogInit(string name)
{
	return Open("Log\\" + name + ".txt");
}

void Log::Enable()
{
	m_bEnabled = true;
}

void Log::Disable()
{
	m_bEnabled = false;
}

string Log::GetTimeStr()
{
	struct tm ptm; 
	time_t tNowTime = time(NULL);
	localtime_s(&ptm, &tNowTime);
	string strFormat = "Now:%Y-%m-%d %H:%M:%S ";	
	char strDateTime[30] = {'\0'};
	strftime(strDateTime, 30, strFormat.c_str(), &ptm);
	string strRes = strDateTime;
	return strRes;
}